﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows;

namespace ShredTheLog.Converters
{
    public sealed class CircleGeometryConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (values != null && values.Length == 2 && values[0] is double && values[1] is double)
            {
                var width = (double)values[0];
                var height = (double)values[1];
                if (width != 0 && height != 0)
                {
                    var radius = Math.Min(width, height) / 2.0;
                    return new EllipseGeometry(new Point(width / 2.0, radius), radius, radius);
                }
                else
                    return null;
            }
            else
                return null;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotSupportedException();
        }

        public static readonly CircleGeometryConverter Default = new CircleGeometryConverter();
    }
}
